roleList = "";

function getRoles() {
	var url = '/stock/pages/system/operator.do?method=getRoles&d=' + new Date();
	$.getJSON(url, {}, function(data) {
		for ( var i = 0; i < data.length; i++) {
			roleList = roleList + '<option value="' + data[i].roleId + '">'
					+ data[i].roleName + '</option>';
		}
	});
}
function callback(data) {
	var str = "";
	for ( var i = 0; i < data.length; i++) {
		// 动态的改变页面中div节点中的内容
		str = str + '<tr><td width="150">' + data[i].operatorName + '</td>'
				+ '<td width="150">' + data[i].employeeName + '</td>'
				+ '<td width="150">' + '<select id="' + data[i].operatorId
				+ '" operatorId="' + data[i].operatorId + '" employeeId="'
				+ data[i].employeeId + '" operatorCid="' + data[i].operatorCid
				+ '" operatorName="' + data[i].operatorName
				+ '" operatorPass="' + data[i].operatorPass + '">'
				+ roleList
				+ '</select></td><td width="133">'
				+ '<input type="button" value="修改" onclick="update('
				+ data[i].operatorId + ');" /></td></tr>';
	}
	$("#operList").html(str);
	for ( var i = 0; i < data.length; i++) {
		document.getElementById(""+data[i].operatorId).value = data[i].roleId
	}
}
function selectAllOper() {
	var url = '/stock/pages/system/operator.do?method=selectOperator&d=' + new Date();
	$.getJSON(url, {}, callback);
}
function update(id) {
	var oper = document.getElementById("" + id);
	var operId = oper.operatorId;
	var operEmpId = oper.employeeId;
	var operCid = oper.operatorCid;
	var operName = oper.operatorName;
	var operPass = oper.operatorPass;
	var roleId = oper.value;

	var url = '/stock/pages/system/operator.do?method=updateOperator&d='
			+ new Date() + '&operatorId=' + operId + '&employeeId=' + operEmpId
			+ '&roleId=' + roleId + '&operatorCid=' + operCid
			+ '&operatorName=' + operName + '&operatorPass=' + operPass;
	$.getJSON(url, {}, callback);
}
function init() {
	getRoles();	
	selectAllOper();
}